﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Windows;
using WpfApp1.DataAccess;
using WpfApp1.Services;
using WpfApp1.ViewModels;
using WpfApp1.Views;

namespace WpfApp1
{
    public partial class App : Application
    {
        private IServiceProvider? ServiceProvider { get; set; }

        protected override void OnStartup(StartupEventArgs e)
        {
            var serviceCollection = new ServiceCollection();
            ConfigureServices(serviceCollection);

            ServiceProvider = serviceCollection.BuildServiceProvider();

            // 将 MainWindow 作为登录界面显示
            var mainWindow = ServiceProvider.GetRequiredService<MainWindow>();
            mainWindow.Show();
        }

        private void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<ITeacherCourseDataAccess, TeacherCourseDataAccess>();
            services.AddSingleton<ITeacherCourseSelectDataAccess, TeacherCourseSelectDataAccess>();
            services.AddSingleton<ITeacherCourseService, TeacherCourseService>();
            services.AddSingleton<ITeacherCourseSelectService, TeacherCourseSelectService>();
            services.AddSingleton<IStuDataAccess, StudentIsDataAccess>();
            services.AddSingleton<IStudentService, StudentService>(); 
            services.AddSingleton<IUDataAccess, UserDataAccess>();
            services.AddSingleton<IUserService, UserService>();
            services.AddSingleton<ICourseService, CourseService>(); 
            services.AddSingleton<ICourseDataAccess, CourseDataAccess>();
            services.AddSingleton<ICourseSelectDataAccess, CourseSelectDataAccess>();
            services.AddSingleton<ICourseSelectService, CourseSelectService>(); 
            services.AddTransient<MainWindow>();
            services.AddTransient<AdminDashboard>();
            services.AddTransient<AdminDashboardViewModel>();
            services.AddTransient<StudentDashboard>();
            services.AddTransient<TeacherDashboard>();

        }
    }
}